package com.xzc.jcip._3_.对象的共享.对象发布;

import java.awt.*;

/**
 * 发布即为对象被外面所见
 * 这里如果发布内部类EventListener，则其doSomething会被外部调用
 * 而此时的ThisEscape对象this还没有构造完成
 */
public class ThisEscape {
    public ThisEscape(EventSource source) {
        source.registerListener(new EventListener() {
            @Override
            public void onEvent(Event e) {
                doSomething(e);
            }
        });
    }

    private void doSomething(Event e) {
        System.out.println(e.id);
    }

    static class EventListener {
        public void onEvent(Event e) {
        }
    }

    public static void main(String[] args) {
        EventSource eventSource = new EventSource();
        ThisEscape thisEscape = new ThisEscape(eventSource);
        System.out.println("are u ok?");
    }
}


